﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpAlgorithm
{
    class NewCalendar
    {
        public NewCalendar()
        {
            int testCount = Int32.Parse(TestConsole.ReadLine());
            for (int testCase = 1; testCase <= testCount; testCase++)
            {
                string[] input = TestConsole.ReadLine().Split(' ');
                long year = long.Parse(input[0]);
                int month = Int32.Parse(input[1]);
                int week = Int32.Parse(input[2]);

                long line = 0;
                long total = year * month;
                line += total / month;
                line += total / week;
                int lcm = Primes.LCM(month, week);
                line -= total / lcm;
                Console.WriteLine("Case #" + testCase + ": " + line);
            }
        }
    }
}
